/**
 * 
 */
package com.home.emp.web;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.home.emp.dao.EmployeeDAO;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xprk339
 *
 */
public class WelcomeController extends MultiActionController {

	private static Logger logger = Logger.getLogger(WelcomeController.class);
	private EmployeeDAO employeeDAO;
	
	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	
	public ModelAndView showEmployees(HttpServletRequest request,HttpServletResponse response,EmployeesView employeesView) throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		List employees = null;
		logger.info("You are in Welcome Controller.");
		logger.info("You are gettng redirected to Index page.");
		employees = employeeDAO.getAllEmployees();			
		logger.info("Number of employees found are : "+ employees.size());
		employeesView.setTitle("All Employees");
		employeesView.setEmployees(employees);
		modelAndView.addObject(employeesView);
		modelAndView.setViewName("index");
		return modelAndView;
	}

	public EmployeeDAO getEmployeeDAO() {
		return employeeDAO;
	}

	public void setEmployeeDAO(EmployeeDAO employeeDAO) {
		this.employeeDAO = employeeDAO;
	}

}
